import java.util.Arrays;

public class MyArraylist {
    public  int[] elme;
    public  int usedSize;
    public  MyArraylist(){
        this.elme=new int[10];
}
    //打印顺序表
    public  void display(){
        for (int i = 0; i < this.usedSize; i++) {
            System.out.println(this.elme[i]+" ");
        }
        System.out.println();
    }
    //获取长度
    public int size(){
        return this.usedSize;
    }
    //在pos位置新增元素
    public  void add(int pos,int data) {
        if (pos<0||pos>usedSize){
            System.out.println("pos位置不合法");
            return;
        }
        if(isFull()){
            this.elme= Arrays.copyOf(this.elme,2*this.elme.length);
        }
        for (int i=this.usedSize-1;i>=pos;i--){
            this.elme[i+1]=this.elme[i];
        }
        this.elme[pos]=data;
        this.usedSize++;
    }
    public  boolean isFull(){
        return this.usedSize==this.elme.length;
    }
    //查找某个元素是否存在
    public  boolean contains(int toFind){
        for (int i = 0; i < usedSize; i++) {
            if (this.elme[i]==toFind){
                return true;
            }
        }
        return false;
    }
    //查找某个元素对应的位置，找不到返回-1
    public  int search(int toFind){
        for (int i = 0; i < usedSize; i++) {
            if (this.elme[i]==toFind){
                return i;
            }
        }
        return -1;
    }
    //查找pos位置的元素
    public  int getPos(int pos){
        if (pos<0||pos>=this.usedSize){
            System.out.println("pos位置不合法");
            return -1;
        }
        if (isEmpty()){
            System.out.println("顺序表为空！");
            return -1;
        }
        return this.elme[pos];
    }
    public boolean isEmpty(){
        return this.usedSize==0;
    }
    //删除某一位置元素
    public  void remove(int toRemove){
        if (isEmpty()){
            System.out.println("顺序表为空！");
            return;
        }
        int index=search(toRemove);
        if (index==-1){
            System.out.println("没有你要删除的数字！");
            return;
        }
        for (int i = index; i <this.usedSize-1 ; i++) {
            this.elme[i]=this.elme[i+1];
        }
        this.usedSize--;
    }
}


























